package cn.qqtheme.framework.picker;

import android.app.Activity;
import android.view.View;
import android.widget.LinearLayout;
import cn.qqtheme.framework.entity.City;
import cn.qqtheme.framework.entity.County;
import cn.qqtheme.framework.entity.Province;
import cn.qqtheme.framework.picker.LinkagePicker;
import cn.qqtheme.framework.util.LogUtils;
import cn.qqtheme.framework.widget.WheelView;
import java.util.ArrayList;
import java.util.List;

/* loaded from: classes.dex */
public class AddressPicker extends LinkagePicker<Province, City, County> {
    private boolean hideCounty;
    private boolean hideProvince;
    private OnAddressPickListener onAddressPickListener;
    private OnWheelListener onWheelListener;
    private ArrayList<Province> provinces;

    /* loaded from: classes.dex */
    public interface OnAddressPickListener {
        void onAddressPicked(Province province, City city, County county);
    }

    /* loaded from: classes.dex */
    public interface OnWheelListener {
        void onCityWheeled(int i, City city);

        void onCountyWheeled(int i, County county);

        void onProvinceWheeled(int i, Province province);
    }

    public AddressPicker(Activity activity, ArrayList<Province> arrayList) {
        super(activity, new AddressProvider(arrayList));
        this.hideProvince = false;
        this.hideCounty = false;
        this.provinces = new ArrayList<>();
        this.provinces = arrayList;
    }

    @Override // cn.qqtheme.framework.picker.LinkagePicker
    public void setSelectedItem(Province province, City city, County county) {
        super.setSelectedItem((AddressPicker) province, (Province) city, (City) county);
    }

    public void setSelectedItem(String str, String str2, String str3) {
        setSelectedItem(new Province(str), new City(str2), new County(str3));
    }

    public Province getSelectedProvince() {
        return this.provinces.get(this.selectedFirstIndex);
    }

    public City getSelectedCity() {
        List<City> cities = getSelectedProvince().getCities();
        if (cities.size() == 0) {
            return null;
        }
        return cities.get(this.selectedSecondIndex);
    }

    public County getSelectedCounty() {
        City selectedCity = getSelectedCity();
        if (selectedCity == null) {
            return null;
        }
        List<County> counties = selectedCity.getCounties();
        if (counties.size() == 0) {
            return null;
        }
        return counties.get(this.selectedThirdIndex);
    }

    public void setHideProvince(boolean z) {
        this.hideProvince = z;
    }

    public void setHideCounty(boolean z) {
        this.hideCounty = z;
    }

    public void setOnWheelListener(OnWheelListener onWheelListener) {
        this.onWheelListener = onWheelListener;
    }

    public void setOnAddressPickListener(OnAddressPickListener onAddressPickListener) {
        this.onAddressPickListener = onAddressPickListener;
    }

    @Override // cn.qqtheme.framework.picker.LinkagePicker
    @Deprecated
    public final void setOnLinkageListener(LinkagePicker.OnLinkageListener onLinkageListener) {
        throw new UnsupportedOperationException("Please use setOnAddressPickListener instead.");
    }

    /* JADX INFO: Access modifiers changed from: protected */
    @Override // cn.qqtheme.framework.picker.LinkagePicker, cn.qqtheme.framework.popup.ConfirmPopup
    public View makeCenterView() {
        if (this.provider == null) {
            throw new IllegalArgumentException("please set address provider before make view");
        }
        float f = this.firstColumnWeight;
        float f2 = this.secondColumnWeight;
        float f3 = this.thirdColumnWeight;
        if (this.hideCounty) {
            this.hideProvince = false;
        }
        if (this.hideProvince) {
            f2 = this.firstColumnWeight;
            f3 = this.secondColumnWeight;
            f = 0.0f;
        }
        this.dividerConfig.setRatio(0.0f);
        LinearLayout linearLayout = new LinearLayout(this.activity);
        linearLayout.setOrientation(0);
        linearLayout.setGravity(17);
        WheelView createWheelView = createWheelView();
        createWheelView.setLayoutParams(new LinearLayout.LayoutParams(0, -2, f));
        linearLayout.addView(createWheelView);
        if (this.hideProvince) {
            createWheelView.setVisibility(8);
        }
        final WheelView createWheelView2 = createWheelView();
        createWheelView2.setLayoutParams(new LinearLayout.LayoutParams(0, -2, f2));
        linearLayout.addView(createWheelView2);
        final WheelView createWheelView3 = createWheelView();
        createWheelView3.setLayoutParams(new LinearLayout.LayoutParams(0, -2, f3));
        linearLayout.addView(createWheelView3);
        if (this.hideCounty) {
            createWheelView3.setVisibility(8);
        }
        createWheelView.setItems(this.provider.initFirstData(), this.selectedFirstIndex);
        createWheelView.setOnItemSelectListener(new WheelView.OnItemSelectListener() { // from class: cn.qqtheme.framework.picker.AddressPicker.1
            /* JADX WARN: Type inference failed for: r1v4, types: [Trd, java.lang.Object] */
            @Override // cn.qqtheme.framework.widget.WheelView.OnItemSelectListener
            public void onSelected(int i) {
                AddressPicker addressPicker = AddressPicker.this;
                addressPicker.selectedFirstIndex = i;
                addressPicker.selectedFirstItem = addressPicker.getSelectedProvince();
                if (AddressPicker.this.onWheelListener != null) {
                    AddressPicker.this.onWheelListener.onProvinceWheeled(AddressPicker.this.selectedFirstIndex, (Province) AddressPicker.this.selectedFirstItem);
                }
                LogUtils.verbose(this, "change cities after province wheeled: index=" + i);
                AddressPicker addressPicker2 = AddressPicker.this;
                addressPicker2.selectedSecondIndex = 0;
                addressPicker2.selectedThirdIndex = 0;
                List<?> linkageSecondData = addressPicker2.provider.linkageSecondData(AddressPicker.this.selectedFirstIndex);
                if (linkageSecondData.size() > 0) {
                    AddressPicker addressPicker3 = AddressPicker.this;
                    addressPicker3.selectedSecondItem = (Snd) linkageSecondData.get(addressPicker3.selectedSecondIndex);
                    createWheelView2.setItems(linkageSecondData, AddressPicker.this.selectedSecondIndex);
                } else {
                    AddressPicker.this.selectedSecondItem = null;
                    createWheelView2.setItems(new ArrayList());
                }
                List<?> linkageThirdData = AddressPicker.this.provider.linkageThirdData(AddressPicker.this.selectedFirstIndex, AddressPicker.this.selectedSecondIndex);
                if (linkageThirdData.size() > 0) {
                    AddressPicker addressPicker4 = AddressPicker.this;
                    addressPicker4.selectedThirdItem = linkageThirdData.get(addressPicker4.selectedThirdIndex);
                    createWheelView3.setItems(linkageThirdData, AddressPicker.this.selectedThirdIndex);
                    return;
                }
                AddressPicker.this.selectedThirdItem = null;
                createWheelView3.setItems(new ArrayList());
            }
        });
        createWheelView2.setItems(this.provider.linkageSecondData(this.selectedFirstIndex), this.selectedSecondIndex);
        createWheelView2.setOnItemSelectListener(new WheelView.OnItemSelectListener() { // from class: cn.qqtheme.framework.picker.AddressPicker.2
            /* JADX WARN: Type inference failed for: r1v5, types: [Trd, java.lang.Object] */
            @Override // cn.qqtheme.framework.widget.WheelView.OnItemSelectListener
            public void onSelected(int i) {
                AddressPicker addressPicker = AddressPicker.this;
                addressPicker.selectedSecondIndex = i;
                addressPicker.selectedSecondItem = addressPicker.getSelectedCity();
                if (AddressPicker.this.onWheelListener != null) {
                    AddressPicker.this.onWheelListener.onCityWheeled(AddressPicker.this.selectedSecondIndex, (City) AddressPicker.this.selectedSecondItem);
                }
                LogUtils.verbose(this, "change counties after city wheeled: index=" + i);
                AddressPicker addressPicker2 = AddressPicker.this;
                addressPicker2.selectedThirdIndex = 0;
                List<?> linkageThirdData = addressPicker2.provider.linkageThirdData(AddressPicker.this.selectedFirstIndex, AddressPicker.this.selectedSecondIndex);
                if (linkageThirdData.size() > 0) {
                    AddressPicker addressPicker3 = AddressPicker.this;
                    addressPicker3.selectedThirdItem = linkageThirdData.get(addressPicker3.selectedThirdIndex);
                    createWheelView3.setItems(linkageThirdData, AddressPicker.this.selectedThirdIndex);
                    return;
                }
                AddressPicker.this.selectedThirdItem = null;
                createWheelView3.setItems(new ArrayList());
            }
        });
        createWheelView3.setItems(this.provider.linkageThirdData(this.selectedFirstIndex, this.selectedSecondIndex), this.selectedThirdIndex);
        createWheelView3.setOnItemSelectListener(new WheelView.OnItemSelectListener() { // from class: cn.qqtheme.framework.picker.AddressPicker.3
            /* JADX WARN: Type inference failed for: r3v1, types: [Trd, cn.qqtheme.framework.entity.County] */
            @Override // cn.qqtheme.framework.widget.WheelView.OnItemSelectListener
            public void onSelected(int i) {
                AddressPicker addressPicker = AddressPicker.this;
                addressPicker.selectedThirdIndex = i;
                addressPicker.selectedThirdItem = addressPicker.getSelectedCounty();
                if (AddressPicker.this.onWheelListener != null) {
                    AddressPicker.this.onWheelListener.onCountyWheeled(AddressPicker.this.selectedThirdIndex, (County) AddressPicker.this.selectedThirdItem);
                }
            }
        });
        return linearLayout;
    }

    @Override // cn.qqtheme.framework.picker.LinkagePicker, cn.qqtheme.framework.popup.ConfirmPopup
    public void onSubmit() {
        if (this.onAddressPickListener != null) {
            this.onAddressPickListener.onAddressPicked(getSelectedProvince(), getSelectedCity(), this.hideCounty ? null : getSelectedCounty());
        }
    }

    /* loaded from: classes.dex */
    private static class AddressProvider implements LinkagePicker.Provider<Province, City, County> {
        private List<Province> firstList = new ArrayList();
        private List<List<City>> secondList = new ArrayList();
        private List<List<List<County>>> thirdList = new ArrayList();

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public boolean isOnlyTwo() {
            return false;
        }

        AddressProvider(List<Province> list) {
            parseData(list);
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<Province> initFirstData() {
            return this.firstList;
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<City> linkageSecondData(int i) {
            if (this.secondList.size() <= i) {
                return new ArrayList();
            }
            return this.secondList.get(i);
        }

        @Override // cn.qqtheme.framework.picker.LinkagePicker.Provider
        public List<County> linkageThirdData(int i, int i2) {
            if (this.thirdList.size() <= i) {
                return new ArrayList();
            }
            List<List<County>> list = this.thirdList.get(i);
            if (list.size() <= i2) {
                return new ArrayList();
            }
            return list.get(i2);
        }

        private void parseData(List<Province> list) {
            int size = list.size();
            int i = 0;
            while (i < size) {
                Province province = list.get(i);
                this.firstList.add(province);
                List<City> cities = province.getCities();
                ArrayList arrayList = new ArrayList();
                ArrayList arrayList2 = new ArrayList();
                int size2 = cities.size();
                for (int i2 = 0; i2 < size2; i2++) {
                    City city = cities.get(i2);
                    city.setProvinceId(province.getAreaId());
                    arrayList.add(city);
                    List<County> counties = city.getCounties();
                    ArrayList arrayList3 = new ArrayList();
                    int size3 = counties.size();
                    int i3 = 0;
                    while (i3 < size3) {
                        County county = counties.get(i3);
                        county.setCityId(city.getAreaId());
                        arrayList3.add(county);
                        i3++;
                        size = size;
                    }
                    arrayList2.add(arrayList3);
                }
                this.secondList.add(arrayList);
                this.thirdList.add(arrayList2);
                i++;
                size = size;
            }
        }
    }
}
